#include <cmath>
#include "Graph.h"
#include "Octagon.h"

namespace Graph_lib{
const double PI=3.14159265;    
Octagon::Octagon(Point c,int r):rr(r){
    add(c);            
}

int Octagon::radius() const{
    return rr;
}

Point Octagon::center() const{
    return point(0);
}

void Octagon::draw_lines() const{
    double fi_step = 2*PI/8;
    double fi = 0;

    vector <Point> vertex;

    while (fi < 2*PI){
        int x1=(int)(point(0).x+rr*cos(fi));
        int y1=(int)(point(0).y+rr*sin(fi));

        vertex.push_back(Point(x1,y1));
        fi+=fi_step;
    }
    if (fill_color().visibility()){
        
        fl_color(fill_color().as_int());
        fl_begin_complex_polygon();

        for (int i=0;i<vertex.size();++i)
            fl_vertex(vertex[i].x, vertex[i].y);

        fl_end_complex_polygon();
        fl_color(color().as_int());    // reset color
    }
    for (int i=0;i < vertex.size()-1;++i)
        fl_line(vertex[i].x,vertex[i].y,vertex[i+1].x,vertex[i+1].y);
    fl_line(vertex[vertex.size()-1].x, vertex[vertex.size()-1].y,
                    vertex[0].x, vertex[0].y);    
}
}
